﻿
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Telerik.WebControls;

using PowerCreator.LMS.DL.Project.Entity;
using PowerCreator.LMS.Web.DL.Project;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Common.Utils;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.Course.Entity;

public partial class Theme_Index_UserClassTasksDealByTeacher : PowerCreator.LMS.Web.Base.WebBasePage
{
    protected string taskid = "0";
    protected string courseid = "0";
    VOTOClassTasks votask = new VOTOClassTasks();
    VOTOUserClassTask vomytask = new VOTOUserClassTask();
    TOClassTasks objtask = new TOClassTasks();
    TOUserClassTask objmytask = new TOUserClassTask();
    Course opCourse = new Course();
    VOTOCourse vocourse = new VOTOCourse();
    TOClass objclass = new TOClass();
    VOTOClass voclass = new VOTOClass();
    VOTOAccessory voaccessory = new VOTOAccessory();
    TOAccessory objaccessory = new TOAccessory();
    VOTOUserClassTask vouserclasstask = new VOTOUserClassTask();
    TOUserClassTask objuserclasstask = new TOUserClassTask();
    VOTOClassTasksReply votaskreply = new VOTOClassTasksReply();
    TOClassTasksReply objtaskReply = new TOClassTasksReply();
    VOTOLearner volearner = new VOTOLearner();
    TOLearner objlearner = new TOLearner();
    VOTOAdvancedUser voadwanceduser = new VOTOAdvancedUser();
    TOAdvancedUser objadwanceduser = new TOAdvancedUser();
    
    PowerCreator.LMS.Web.DL.User.LoginEntity login = new PowerCreator.LMS.Web.DL.User.LoginEntity();
    protected string UserTask_ID = "0";
    private string TReply_Id = "0";
    protected string classID = "0";
    protected string courseListID = "0";

    protected void Page_Load(object sender, EventArgs e)
    {
        login = (PowerCreator.LMS.Web.DL.User.LoginEntity)Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO];

        if (Request.QueryString["CourseID"] != null)
        {
            courseid = Request.QueryString["CourseID"].ToString();
            ViewState["CourseID"] = courseid;
            //vocourse = opCourse.LoadVOTCourse(int.Parse(courseid));
            //lbl_course.Text = vocourse.CourseName;
        }
        if (Request.QueryString["TaskID"] != null)
        {
            taskid = Request.QueryString["TaskID"].ToString();
            ViewState["TaskID"] = taskid;
            votask = objtask.Load(int.Parse(taskid));
            lbl_TaskTitle.Text = votask.TasksTitle;
            lbl_TaskTitleInfo.Text = votask.TasksTitle;
            lbl_TaskContent.Text = votask.TasksContent;
            if (votask.Accessory != null)
            {
                voaccessory = objaccessory.Load(votask.Accessory);
                lbl_TaskAccessory.Text = "<a href=\"" + voaccessory.Url + "\" target=\"_blank\">" + voaccessory.Title + "</a>";
            }
            else
            {
                lbl_TaskAccessory.Text = "无";
            }

            lbl_endtime.Text = votask.EndDate.ToString().Replace(" 0:00:00", ""); ;
            //BinderPage(lbl_endtime.Text);
        }

        if (Request.QueryString["UserTask_ID"] != null)
        {
            UserTask_ID = Request.QueryString["UserTask_ID"].ToString();
            ViewState["UserTask_ID"] = UserTask_ID;
            vouserclasstask = objuserclasstask.Load(int.Parse(UserTask_ID));
            lbl_MyTaskTitle.Text = vouserclasstask.Title;
            lbl_MyTaskContent.Text = vouserclasstask.Content;
            lbl_Finishtime.Text = vouserclasstask.CreateDate.ToString();

            if (vouserclasstask.Accessory != null)
            {
                voaccessory = objaccessory.Load(vouserclasstask.Accessory);
                lbl_MyTaskAccessory.Text = "<a href=\"" + voaccessory.Url + "\" target=\"_blank\">" + voaccessory.Title + "</a>";
            }
            else
            {
                lbl_MyTaskAccessory.Text = "无";
            }

            volearner = objlearner.Load(vouserclasstask.Creator);
            lbl_UserName.Text = volearner.Name;

            BinderGVTeacher(int.Parse(UserTask_ID));
           
        }

        if (Request.QueryString["ClassID"] != null)
        {
            classID = Request.QueryString["ClassID"].ToString();
            ViewState["ClassID"] = classID;
            voclass = objclass.Load(int.Parse(classID));
            lbl_ClassName.Text = voclass.Name;
            //lbl_Class.Text = voclass.Name;
        }
        if (Request.QueryString["CourseListID"] != null)
        {
            courseListID = Request.QueryString["CourseListID"].ToString();
            ViewState["CourseListID"] = courseListID;
        }

        
    }

    private void BinderGVTeacher(int id)
    {
        DataTable dt = new DataTable();
        string sql=" ReplyType=1 and UserTask_Id="+id.ToString();
        dt = objtaskReply.Query(sql);
        dt.Columns.Add("Name");
        dt.Columns.Add("AccessoryName");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            voadwanceduser=objadwanceduser.Load(int.Parse(dt.Rows[i]["Creator"].ToString()));
            dt.Rows[i]["Name"] = voadwanceduser.Name;
            if (dt.Rows[i]["Accessory"] != null)
            {
                if (dt.Rows[i]["Accessory"].ToString().Trim().Length > 0)
                {
                    voaccessory = objaccessory.Load(int.Parse(dt.Rows[i]["Accessory"].ToString()));
                    dt.Rows[i]["AccessoryName"] = "<a href=\"" + voaccessory.Url + "\" target=\"_blank\">" + voaccessory.Title + "</a>";
                }
                else
                {
                    dt.Rows[i]["AccessoryName"] = "无";
                }
            }
            else
            {
                dt.Rows[i]["AccessoryName"] = "无";
            }
        }
        gv_TeacherReply.DataSource = dt;
        gv_TeacherReply.DataBind();
    }

    
}
